package com.jt.tenant.conn;

import com.jt.tenant.app.JTApplication;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by AD on 2016/5/12.
 */
@HttpInlet(Conn.INLET_GET_GAS_STATION_LIST)
public class GetGasStationList extends JTAsyGet<GetGasStationList.Info> {
    public String token = JTApplication.jtPreferences.readToken();
    public String userId = JTApplication.jtPreferences.readUserID();
    public String area_code = "01";

    public GetGasStationList(AsyCallBack<Info> asyCallBack) {

        super(asyCallBack);

    }

    @Override
    protected Info parser(JSONObject object) {
        JSONObject apiTYF = object.optJSONObject("apiTYF");

        JSONObject head = apiTYF.optJSONObject("head");

        Info info = new Info();

        info.msg = head.optString("msg");

        JSONObject body = apiTYF.optJSONObject("body");

        JSONArray gasStationList = body.optJSONArray("gsList");

        info.code = body.optString("code");

        info.logourl = body.optString("logoUrl");

        if(gasStationList!=null){
            for (int i=0;i<gasStationList.length();i++){
                JSONObject object_gs = gasStationList.optJSONObject(i);
                GSList gsList = new GSList();
                gsList.ID = object_gs.optString("id");
                gsList.GAS_NAME = object_gs.optString("gas_name");
                gsList.GAS_ADDRESS = object_gs.optString("gas_address");
                gsList.GAS_PHONE = object_gs.optString("gas_phone");
                gsList.GAS_LON = object_gs.optString("gas_lon");
                gsList.GAS_LAT = object_gs.optString("gas_lat");
                gsList.REMARKS = object_gs.optString("remarks");
                gsList.AREA_CODE = object_gs.optString("area_code");
                gsList.FLAG = object_gs.optString("flag");
                gsList.URL = object_gs.optString("url");
                if(!gsList.FLAG.equals("0")){
                    JSONObject object_order = object_gs.optJSONObject("GasLog");
                    gsList.GASLOG.gasCode = object_order.optString("gasCode");
                    gsList.GASLOG.gasTotalMoney = object_order.optString("gasTotalMoney");
                }
                info.gsLists.add(gsList);
            }
        }else{
            TOAST = "暂无加油站店提供服务";
        }

        return info;
    }

    public static class Info{
        public String msg;
        public String code;
        public String logourl;
        public List<GSList> gsLists = new ArrayList<>();

    }

//    "id": "130",
//            "gasBoyCreatetime": "",
//            "gasBoyCount": "200.0",
//            "gasShopId": "1",
//            "gasBoyId": "0",
//            "gasTypeId": "1",
//            "userId": "798",
//            "gasTotalMoney": "1206",
//            "gasSalePrice": "6.03",
//            "gasTotalsaleMoney": "1206",
//            "gasCode": "BY1463551739",
//            "gasFavorablePrice": "60.0",
//            "gasCarNumber": "",
//            "gasState": "0",
//            "plateNumber": "",
//            "gasAppointmentTime": "1463551739000",
//            "gasPayCode": "",
//            "gasChannel": "0",
//            "phone": "18604602101",
//            "pay_time": ""

    public static class GasLog{

        public String id,gasBoyCreatetime,gasBoyCount,gasShopId,gasBoyId,gasTypeId,user_id;
        public String gasTotalMoney,gasSalePrice,gasTotalsaleMoney,gasCode,gasFavorablePrice,gasCarNumber,gasState,plateNumber;
        public String gasAppointmentTime,gasPayCode,gasChannel,gas_phone,pay_time;

    }
    public static class GSList implements Serializable{
        public String  ID,GAS_NAME,GAS_ADDRESS,GAS_PHONE,GAS_LON,GAS_LAT,REMARKS,AREA_CODE,FLAG,URL;
        public GasLog GASLOG = new GasLog();

    }
}
